home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 412_01 / demos / demo5.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-28  |  1.7 KB  |  76 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "graph.h"
  5.  
  6.  
  7. /*                  DEMO5
  8.  
  9.     In this problem we want to find the shortest route from city
  10.     X to city Y. Therefore, we design a class PATH_ derived from
  11.     class UNICOST_GRAPH which performs a uniform cost search
  12.     and consequently we need to implement function compute_g().
  13.  
  14.     Because of the nature of this problem we don't make use
  15.     of function do_operator(), buf of expand() instead.
  16.  
  17. */
  18.  
  19.  
  20.  
  21.  
  22. /*            ROUTE_
  23.  
  24.     We define a struct ROUTE_ to be able to easily store the
  25.     'map info': pairs of cities and the distance between them.
  26.  
  27. */
  28.  
  29. typedef struct ROUTE_
  30. {
  31.     char
  32.         *from,
  33.         *to;
  34.     int
  35.         distance;
  36. } ROUTE_;
  37.  
  38.  
  39.  
  40. /*                    CITY_
  41.  
  42.     Class CITY_ defines objects that represent the cities that are
  43.     visited during the search. Since we want to perform a uniform
  44.     cost search we must derive class CITY_ from class UNI_NODE_.
  45.  
  46. */
  47.  
  48. class CITY_ : public UNI_NODE_
  49. {
  50.     public:
  51.         CITY_(const char *, int);
  52.         const char *getcity() const;
  53.         int getdist() const;
  54.  
  55. // implementation of virtual functions
  56.         int equal(const VOBJECT_ &) const;
  57.         void display() const;
  58.         NODE_ *expand(int) const;
  59.     private:
  60.         const char
  61.             *city;       // current city visited
  62.         int
  63.             dist;        // distance from city X, the city directly next to
  64.                          // this city, to this city
  65. };
  66.  
  67.  
  68. class PATH_ : public UNICOST_GRAPH_
  69. {
  70.     public:
  71.         PATH_(CITY_ *start, CITY_ *target);
  72.         int compute_g(const NODE_ &);
  73. };
  74.  
  75.  
  76.